package cn.training.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@Controller("HelloWorldController")
@RequestMapping("/")
public class HelloWorldController {
	@Autowired
	helloworldservice helloworld;
	
	//yonghudenglu
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String initLogin(Model model) {
        return "index";
    } 
    @RequestMapping(value = "/init", method = RequestMethod.POST)
    public String initLogin1(UserBean userBean,Model model) {
    	UserBean result=helloworld.chusersear(userBean);
    	if(result!=null)
    	{List<UserBean> list=helloworld.nameall(result);
    		model.addAttribute("list",list);
    	return "list";
    	}
    	else
    	{String message="input effor";
    	model.addAttribute("message", message);
        return "index";  
    }
    	}
 
    /*
    @RequestMapping(value = "/init1", method = RequestMethod.POST)
    public String inserLogin1(UserBean userBean) {
		if(helloworld.searchinsert(userBean)!=0)
			return"insertpage";

    	  else return "helloworld";		
    }
    @RequestMapping(value = "/name", method = RequestMethod.POST)
    public String nameLogin1(UserBean userBean,Model model) {
    	UserBean result=helloworld.searchname(userBean);
    	model.addAttribute("UserBean",result);
    	
        return "login";  
    }
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String updateLogin1(UserBean userBean) {
		if(helloworld.updateUser(userBean)!=0)
			return"insertpage";

    	  else return "helloworld";		
    }
    
    
    */
    @RequestMapping(value = "/all", method = RequestMethod.POST)
    public String selectall(UserBean userBean,Model model) {
    	List<UserBean> result=helloworld.nameall(userBean);
    	model.addAttribute("list",result);
    	
        return "list";  
    }
}


 
   